package logic

import (
	"MyBlogv2/blog-common/HttpCode"
	"MyBlogv2/blog-common/models"
	"context"
	"github.com/jinzhu/copier"

	"MyBlogv2/Servers/UserAction/internal/svc"
	"MyBlogv2/Servers/UserAction/userAction"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddTreeHoleLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddTreeHoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddTreeHoleLogic {
	return &AddTreeHoleLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddTreeHoleLogic) AddTreeHole(in *UserAction.AddTreeHoleRequest) (*UserAction.CommonResponse, error) {

	var treeHole models.TreeHole
	copier.Copy(&treeHole, in)
	err := models.Db.Model(new(models.TreeHole)).Create(&treeHole).Error
	if err != nil {
		return &UserAction.CommonResponse{
			Code: int64(HttpCode.FAILURE),
		}, nil
	}
	return &UserAction.CommonResponse{
		Code: int64(HttpCode.SUCCESS),
	}, nil
}
